import torch

# 创建一个矩阵
matrix = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float32)

# 计算矩阵的秩
rank = torch.linalg.matrix_rank(matrix)
print("矩阵的秩:", rank)